package _220323;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author ShadowLim
 * @create 2022-03-23-11:30
 */
public class 蓝肽子序列 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.next();
        String s2 = scanner.next();
        scanner.close();
        StringBuilder sb = new StringBuilder();
        List<String> l1 = new ArrayList<>();
        List<String> l2 = new ArrayList<>();

        for (int i = 0; i < s1.length();) {
            sb.setLength(0);
            sb.append(s1.charAt(i++));
            while (i < s1.length() && s1.charAt(i) > 90) {  // 大写字母Z的ASCII码为90
                sb.append(s1.charAt(i++));
            }
            l1.add(sb.toString());
        }

        for (int i = 0; i < s2.length();) {
            sb.setLength(0);    // 清空sb中的s1字符串 追加s2字符串
            sb.append(s2.charAt(i++));
            while (i < s2.length() && s2.charAt(i) > 90) {  // 大写字母Z的ASCII码为90
                sb.append(s2.charAt(i++));
            }
            l2.add(sb.toString());
        }

        int[][] dp = new int[l1.size() + 1][l2.size() + 1];
        for (int i = 1; i <= l1.size(); i++) {
            String c1 = l1.get(i - 1);
            for (int j = 1; j <= l2.size(); j++) {
                if (c1.equals(l2.get(j - 1))) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
        System.out.println(dp[l1.size()][l2.size()]);
    }
}
